package com.fsnbigdata.repository;

import com.fsnbigdata.domain.ZhExpert;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author: chen quan zhou
 * @Date: Created in 19:01 2018/9/29
 * @Modified By:
 */
public interface ZhExpertRepository extends JpaRepository<ZhExpert,Long> {

    Page<ZhExpert> findAll(Specification<ZhExpert> sp, Pageable pageable);

    @Query(value = "select z from ZhExpert z where type=?1 ")
    List<ZhExpert> findAllByType(Integer type);

    @Query(value = "select * from zh_expert where if(?1!='',type=?1,1=1) ORDER BY ?#{#pageable}",
            countQuery = "select count(*) from zh_expert where if(?1!='',type=?1,1=1)",
            nativeQuery = true)
    List<ZhExpert> queryList(String type,Pageable pageable);

    @Query(value = "select count(*) from zh_expert where if(?1!='',type=?1,1=1)",nativeQuery = true)
    Long getCount(String type);

    @Query(value = "select * from zh_expert where if(?1!='',creator=?1,1=1)",nativeQuery = true)
    List<ZhExpert> getListByCreator(String creator);
}
